/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.mysql;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author admin
 */
import com.objects.user;

public class mysqlUser {

 
    public static user getUserByUsername (String username) throws Exception
    {
        mysqlConnector con = new mysqlConnector();
        try
        {
            Statement state = con.verbMySQL.createStatement();
            ResultSet result = state.executeQuery("SELECT * FROM TBLUser WHERE UserName='"+username+"'");
            if (result.next())
            {
                
                return new user(result.getString(2), result.getString(4), result.getString(3), result.getInt(1));
            }
            else
            {
                return null;
            }

        }
        catch (SQLException ex)
        {
             Logger.getLogger(mysqlUser.class.getName()).log(Level.SEVERE,null,ex);

        }
        finally
        {
            con.verbMySQL.close();
        }
        return null;
    }

    public static boolean checkLogin (String username,String password) throws Exception
    {
        mysqlConnector con = new mysqlConnector();
        try
        {
            Statement state = con.verbMySQL.createStatement();
            ResultSet result = state.executeQuery("SELECT * FROM TBLUser WHERE UserName='"+username+"' AND UserPasswort='"+password+"'");
            if (result.next())
            {

                return true;
            }
            else
            {
                return false;
            }
        }
        catch (SQLException ex)
        {
             Logger.getLogger(mysqlUser.class.getName()).log(Level.SEVERE,null,ex);

        }
        finally
        {
            con.verbMySQL.close();
        }
        return false;
    }


   
}
